<template>
  <div class="app-container">
    <section>
      <!--工具条-->
      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form :inline="true" :model="formInline">
          <el-form-item label="商品名称 ">
            <el-input v-model="formInline.SKUName" placeholder="商品名称" maxlength="8" ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" >查询</el-button>
          </el-form-item>
        </el-form>
      </el-col>

      <el-table
        :data="skulist"
        v-loading="skulistLoading"
        element-loading-text="拼命加载中"
        fit
        highlight-current-row
        border
        style="width: 100% "
      >
        <el-table-column prop="SKUName" label="商品名称" align="center"></el-table-column>
        <el-table-column prop="SKUUnitNo" label="单位" align="center"></el-table-column>
        <el-table-column prop="SKUInPrice" label="进价" align="center"></el-table-column>
        <el-table-column prop="SKUSalePrice" label="销售价" align="center"></el-table-column>
        <el-table-column prop="SKUWholesalePrice" label="批发价" align="center"></el-table-column>
        <el-table-column prop="SKUCombinationPrice" label="折扣率" align="center"></el-table-column>
        <el-table-column prop="Specification" label="规格" align="center"></el-table-column>
        <el-table-column prop="PurchaseRate" label="商品系数" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.PurchaseRate" 
           placeholder="请输入内容" maxlength="6"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="250">
          <template slot-scope="scope">
            <el-button type="primary" @click="UpdatePurchaseRate(scope.row)">修改系数</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        background
        layout=" prev, pager, next, jumper"
        @current-change="handleCurrentChange"
        :page-size="pageSize"
        :total="total"
        style="float:right ;margin-top: 10px;"
      ></el-pagination>
    </section>
  </div>
</template>

<script>
import { SKUList, UpdatePurchaseRate } from "@/api/api";
import Config from "../../api/config";
export default {
  data() {
    return {
      //商品属性
      SKUPropertyList: [
        {
          SKUProperty: 0,
          SKUPropertyName: "未指定"
        },
        {
          SKUProperty: 1,
          SKUPropertyName: "食品"
        },
        {
          SKUProperty: 2,
          SKUPropertyName: "非食品"
        }
      ],

      //销售方式
      SKUSaleModeList: [
        {
          SKUSaleMode: 0,
          SKUSaleModeName: "未指定"
        },
        {
          SKUSaleMode: 1,
          SKUSaleModeName: "普通"
        },
        {
          SKUSaleMode: 2,
          SKUSaleModeName: "电子秤"
        }
      ],

      ProductId: "",
      status: -1,
      typeid: 1,
      skulist: [],
      SupplierList: [],
      OderVisible: false,
      editFormVisible: false,
      editForm: {},
      addLoading: false,
      addFormVisible: false,
      addForm: {},
      list: [],
      page: 1,
      pageSize: 10,
      total: 0,
      formInline: {
        SKUId: "",
        SKUName: ""
      }
    };
  },
  created() {
    this.getSkuList();
  },
  methods: {
   
 
    //获取商品列表
    getSkuList() {
      var self = this;
      var para = {
        sessionid: JSON.parse(localStorage.getItem("userinfo")).SessionId,
        page: this.page,
        pagesize: this.pageSize
      };
      this.skulistLoading = true;
      SKUList(para).then(res => {
        if (res.data.Status != 1) {
          this.$message({
            message: res.data.Description,
            type: "error"
          });
          return;
        } else {
          var vdata = JSON.parse(Base64.decode(res.data.Data));
          console.log("输出商品列表", vdata);
          self.skulist = vdata.DataList;
          self.total = vdata.TotalCount;
        }
        self.skulistLoading = false;
      });
    },

    //获取商品列表
    UpdatePurchaseRate(row) {
      var self = this;
      var para = {
        sessionid: JSON.parse(localStorage.getItem("userinfo")).SessionId,
        ProductId: row.ProductId,
        PurchaseRate: row.PurchaseRate
      };
      UpdatePurchaseRate(para).then(res => {
        if (res.data.Status != 1) {
          this.$message({
            message: res.data.Description,
            type: "error"
          });
          return;
        } else {
          this.$message({
            message: res.data.Description,
            type: "Success"
          });
          this.getSkuList();
          return;
        }
      });
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getSkuList();
    }
  }
};
</script>

<style>
</style>